<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\DB;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Comment>
 */
class CommentFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition()
    {
        $content = '';
        $paras = fake()->paragraphs(fake()->numberBetween(1,3));
        foreach($paras as $para){
            $content .= "<p>".$para."</p>";
        }
        $post_id = fake()->randomElement(DB::table('posts')->pluck('id'));
        $comments_ids = DB::table('comments')->where('post_id',$post_id)->pluck('id');
        echo count($comments_ids);
        $reply_to_comment_id = null;
        if(fake()->numberBetween(1,3)==2){
            $reply_to_comment_id = fake()->randomElement($comments_ids);
        }
        return [
            'content' => $content,
            'post_id' => $post_id,
            'user_id' => fake()->numberBetween(1,DB::table('users')->max('id')),
            'reply_to_comment_id'=>$reply_to_comment_id
        ];
    }
}
